/**************************************************************************************
 *  Copyright (c)  2010  Leszek Karcz, Changmin Bae.
 *  Permission is granted to copy, distribute and/or modify this document
 *  under the terms of the GNU Free Documentation License, Version 1.3
 *  or any later version published by the Free Software Foundation;
 *  with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 *  A copy of the license is included in the section entitled "GNU
 *  Free Documentation License". 
 **************************************************************************************/
package data.tileables;
import main.*;
import data.Map;
import data.Player;
import data.missions.*;

/**************************************************************************************
 * Author(s): Leszek Karcz, Changmin Bae
 * Explorer unit, can discover resources on the map when in retrospect mode
 **************************************************************************************/
public class Explorer extends Unit
{
	public static final int [] PRICE = { 20, 5, 5 };
	public static final int BUILDTIME = 5;
	private boolean prospecting;
		
	/**************************************************************************************
	 * Author(s): Leszek Karcz, Changmin Bae
	 * Explorer constructor
	 **************************************************************************************/
	public Explorer(int ID, int supertypeID, Player player)
	{
		super(ID, supertypeID, player);
		this.setType("Explorer");
		this.setImage("unit_explorer");
		this.setIcon("unit_explorer");
		this.setStats(10, 10, 1, 1, 1, 2);
		
		this.setNumberOfCommands(4);
		this.prospecting=false;
		
		this.setUpkeep(new int[]{4,1,4});
		this.setAllocationRate( 1, 1, 1);
	}
	
	/**************************************************************************************
	 * Author(s): Leszek Karcz
	 * returns how many tick it takes to move by 1 tile, in retrospect mode explorer requires
	 * twice as much ticks to move by 1 tile
	 **************************************************************************************/
	public int getMovementTicks()
	{
		if(this.prospecting)
		{
			return super.getMovementTicks();
		}
		else
		{
			return super.getMovementTicks()*2;
		}
	}
	
	/**************************************************************************************
	 * Author(s): Leszek Karcz
	 * returns whether the explorer is in retrospect mode
	 **************************************************************************************/
	public boolean isProspecting()
	{
		return this.prospecting;
	}	
	
	/**************************************************************************************
	 * Author(s): Changmin Bae
	 * executes instructions regarding currently selected command
	 * 0 - Go to rally#
	 * 1 - Decomission
	 * 2 - Power up / down
	 * 3 - Normal mode / Prospecting mode
	 **************************************************************************************/
	public boolean enqueueSelectedCommand(String mode, Map m, int x, int y)
	{
		this.clearMissions();
		
		switch(this.getSelectedCommand()){
		case 0:
			try  
			{  
				this.addMission(new MoveToRally(this, m, player, Integer.parseInt(mode)));
			}
			catch(Exception e){}
			break;
		case 1:
			this.die();
			break;
		case 2:
			
			if(this.getState() == 0)
				this.addMission(new PowerUpUnit(this));
			else
				this.addMission(new PowerDownUnit(this));
			break;
		case 3:
			if(!this.prospecting)
				this.prospecting = true;
			else
				this.prospecting = false;
			break;
		}
		
		return true;
	}
	
	/**************************************************************************************
	 * Author(s): Leszek Karcz, Changmin Bae
	 * returns list of possible commands
	 **************************************************************************************/
	public String[] getCommandsText()
	{
		return new String[]{"Go to rally #","Decommision",(this.getState()==0 ? "Power up" : "Power down"),(this.isProspecting() ? "Normal mode" : "Prospecting mode")};
	}
	
	/**************************************************************************************
	 * Author(s): Eric Martin-Taylor
	 * starts Prospecting
	 **************************************************************************************/
	public void startProspecting()
	{
		this.prospecting = true;
	}	
	
	/**************************************************************************************
	 * Author(s): Eric Martin-Taylor
	 * stops Prospecting
	 **************************************************************************************/
	public void stopProspecting()
	{
		this.prospecting = false;
	}

	public void die()
	{ 
		super.die();
		player.removeExplorer(this);
	}
}
